﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;

namespace AnyOffice.general.meeting.room
{
    public partial class edit : ModulePage
    {

 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int roomId = (Request.QueryString["room_id"] != null) ? int.Parse(Request.QueryString["room_id"]) : 0;
                this.ViewState["RoomId"] = roomId;
                DataTable table = new MeetingRoomDao().SelectByRoomId(base.Conn, roomId);
                if (table.Rows.Count == 0)
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowPrompt("无此会议室！", "index.aspx");
                    return;
                }
                this.txtName.Value = (table.Rows[0]["Name"] != DBNull.Value) ? table.Rows[0]["Name"].ToString() : "";
                this.txtName.Value = (table.Rows[0]["Name"] != DBNull.Value) ? table.Rows[0]["Name"].ToString() : "";
                this.txtCapacity.Value = (table.Rows[0]["Capacity"] != DBNull.Value) ? table.Rows[0]["Capacity"].ToString() : "";
                this.txtDevice.Value = (table.Rows[0]["Device"] != DBNull.Value) ? table.Rows[0]["Device"].ToString() : "";
                this.txtDescription.Value = (table.Rows[0]["Description"] != DBNull.Value) ? table.Rows[0]["Description"].ToString() : "";
                this.txtPlace.Value = (table.Rows[0]["Place"] != DBNull.Value) ? table.Rows[0]["Place"].ToString() : "";
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                MeetingRoomDao dao2 = new MeetingRoomDao();
                MeetingRoomData data = new MeetingRoomData();
                data.RoomId = Convert.ToInt32(this.ViewState["RoomId"]);
                data.Name = this.txtName.Value;
                if (this.txtCapacity.Value != string.Empty)
                {
                    data.Capacity = this.txtCapacity.Value;
                }
                if (this.txtDevice.Value != string.Empty)
                {
                    data.Device = this.txtDevice.Value;
                }
                if (this.txtDescription.Value != string.Empty)
                {
                    data.Description = this.txtDescription.Value;
                }
                if (this.txtPlace.Value != string.Empty)
                {
                    data.Place = this.txtPlace.Value;
                }
                dao2.Update(base.Conn, data);
                this.litMessage.Text = base.ShowPrompt("修改会议室成功！", "index.aspx");
            }
        }
 

    }
}
